package com.whx.managea.controller;

import com.whx.managea.entity.Group;
import com.whx.managea.service.GroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("group")
public class GroupController {

    @Autowired
    private GroupService groupService;

    //定义用来查询所有小组
    @RequestMapping("findAll")
    public String findAll(Model model){
        List<Group> groups = groupService.findAll();
        model.addAttribute("groups",groups);
        //跳转页面
        return "back/group/index";
    }

    //定义用来保存小组信息
    @RequestMapping("save")
    public String save(Group group){
        groupService.save(group);
        return "redirect:/group/findAll";
    }

    //定义一个请求。用来根据用户传递的班级id查询对应的小组信息
    @RequestMapping("findAllJSON")
    @ResponseBody
    public List<Group> findAllJSON(String id){
        return groupService.findByClazzId(id);
    }
}
